//
//  PosterCollectionView.m
//  HWmovie
//
//  Created by Mac on 15/7/24.
//  Copyright (c) 2015年 杨梦佳. All rights reserved.
//

#import "PosterCollectionView.h"

#import "PosterCollectionViewCell.h"
#import "common.h"
#import "UIViewExt.h"
#import "MovieModel.h"
@implementation PosterCollectionView


-(instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    
    self=[super initWithFrame:frame collectionViewLayout:layout];
    
    if (self) {
        
        self.delegate=self;
        self.dataSource=self;
        
        self.pagingEnabled=YES;
        
        
        [self registerClass:[PosterCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        
        
    }
    return self;
    
}

-(void)setModalArray:(NSArray *)modalArray
{
    _modalArray=modalArray;
    [self reloadData];
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return  _modalArray.count;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PosterCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    
    
    MovieModel  *modal=_modalArray[indexPath.row];
    NSDictionary *dic= modal.images;
    
    
    
    cell.urlImage=dic[@"large"];
    
    cell.backgroundColor=[UIColor   greenColor];
    return cell;
    
    
    
}



-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
  //  NSLog(@"%f %f",kwidth*0.75, self.height);
    return CGSizeMake(kwidth*0.75, self.height);
    
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    
    return UIEdgeInsetsMake(0, kwidth*0.15, 0,  kwidth*0.15);
    
    
}
/***************代理****************/
//滚动时调用
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    NSLog(@"滚动开始");
//    // NSLog(@"%f %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
//}
//
////停止拖动，手指离开
//-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
//{
//    
//    NSLog(@"停止 拖动，手指离开");
//    
//    
//}

//将要减速
//- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
//{
//    NSLog(@"将要减速");
////    CGFloat x=scrollView.contentOffset.x;
////    CGFloat y=scrollView.contentOffset.y;
////    
////    
////    scrollView.contentOffset=CGPointMake(x-50, y);
////    
////    NSLog(@"%f %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
//// 
//    
//}

//停止减速
//-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView1
//{
//    NSLog(@"停止减速");
//    NSLog(@"%f %f",scrollView1.contentOffset.x,scrollView1.contentOffset.y);
//    
//}
//
//- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
//{
//    NSLog(@"111");
//}



@end
